const Router = require('koa-router')

const { auth, hadAdminPermission } = require('../middleware/auth.middleware')
const { validator, validateQuery } = require('../middleware/goods.middleware')

const {
  upload,
  create,
  update,
  remove,
  offGood,
  onGood,
  findAll,
} = require('../controller/good.controller')

const router = new Router({ prefix: '/goods' })

router.post('/upload', auth, hadAdminPermission, upload)

router.post('/', auth, hadAdminPermission, validator, create)

router.put('/:id', auth, hadAdminPermission, validator, update)

// 硬删除
router.delete('/:id', auth, hadAdminPermission, remove)

// 软删除
// 下架
router.post('/:id/off', auth, hadAdminPermission, offGood)
// 上架
router.post('/:id/on', auth, hadAdminPermission, onGood)

// 商品列表
router.get('/', validateQuery, findAll)

module.exports = router
